package com.tensquare.qa.dao;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 数据访问接口
 *
 * @author Administrator
 */
public interface ProblemDao extends JpaRepository<Problem, String>, JpaSpecificationExecutor<Problem> {
    //最新
    //nativeQuery = true 是否使用sql语句
    @Query(value = "SELECT * FROM tb_problem WHERE id IN (SELECT problemid FROM tb_pl WHERE labelid = ?1) ORDER BY replytime DESC", nativeQuery = true)
    public List<Problem> newList(String labelid, PageRequest pageRequest);

    //热门
    @Query(value = "SELECT * FROM tb_problem WHERE id IN (SELECT problemid FROM tb_pl WHERE labelid = ?1) ORDER BY reply DESC", nativeQuery = true)
    public List<Problem> hotList(String labelid, PageRequest pageRequest);

    //等待
    @Query(value = "SELECT * FROM tb_problem WHERE id IN (SELECT problemid FROM tb_pl WHERE labelid = ?1) AND reply = 0 ORDER BY createtime DESC;", nativeQuery = true)
    public List<Problem> waitList(String labelid, PageRequest pageRequest);

}
